package com.rc.saas.mini.hlhtcec2.service;

import com.alibaba.fastjson.JSON;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.rc.saas.mini.common.constant.HttpConstant;
import com.rc.saas.mini.hlhtcec2.config.HlhtBizPubFetchTool;
import com.rc.saas.mini.hlhtcec2.config.HlhtConfig;
import com.rc.saas.mini.model.hlhtsk.HlhtskBizOperator;
import com.rc.saas.mini.model.hlhtsk.HlhtskBizTenant;
import com.rc.saas.mini.vo.cec.StdRequest;
import com.rc.saas.mini.vo.hlhtcec2.*;
import org.apache.commons.lang3.StringUtils;
import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.client.ResponseHandler;
import org.apache.http.client.fluent.Request;
import org.apache.http.entity.StringEntity;
import org.apache.http.util.EntityUtils;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.springframework.stereotype.Service;

import java.io.IOException;
import java.text.SimpleDateFormat;

/**
 * @author wangzhengwei
 * @create 2021/12/23
 */
@Service
public class HlhtBiz2NotifyServiceImpl implements HlhtBiz2NotifyService {
    private static Logger logger = LogManager.getLogger(HlhtBiz2NotifyServiceImpl.class);
    //加密时间戳格式
    private final SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmss");

    @Override
    public TokenResult assembleTokenResult(HlhtskBizOperator bizOperator, HlhtskBizTenant bizTenant) {
        String URL = bizOperator.getHlhtUrl2() + HlhtConfig.QUERY_TOKEN2;

        try {
            TokenReq tokenReq = new TokenReq();
            if (bizOperator.getLicenseTenantCode() != null){
                tokenReq.setOperatorID(bizOperator.getLicenseTenantCode());
            }else {
                tokenReq.setOperatorID(bizOperator.getTenantCode());
            }
            tokenReq.setOperatorSecret(bizOperator.getOperatorSecret());
            ObjectMapper objectMapper = new ObjectMapper();
            String enData = objectMapper.writeValueAsString(tokenReq);
            logger.info(bizOperator.getTenantCode() + "-" + bizOperator.getHlhtOperatorId() + ":assembleTokenResult 加密前:{}", enData);

            //使用对方密钥加密
            String retdata = HlhtBizPubFetchTool.genDDEncodeData2(bizOperator, enData);

            //使用对方密钥签名
            String timeStamp = sdf.format(System.currentTimeMillis());
            String sig = HlhtBizPubFetchTool.genDDSig2(bizOperator, retdata, timeStamp);

            StdRequest resp = genSuccessResp2(retdata, bizOperator, sig, timeStamp);

            String respData = objectMapper.writeValueAsString(resp);

            logger.info(bizOperator.getTenantCode() + "-" + bizOperator.getHlhtOperatorId() + ":assembleTokenResult 请求,:{},:{}", respData, URL);

            return Request.Post(URL)
                    .addHeader("Content-Type", HttpConstant.CONTENT_TYPE_JSON)
                    .body(new StringEntity(respData))
                    .execute()
                    .handleResponse(new ResponseHandler<TokenResult>() {
                        @Override
                        public TokenResult handleResponse(HttpResponse httpResponse) throws IOException {
                            int code = httpResponse.getStatusLine().getStatusCode();

                            logger.info(bizOperator.getTenantCode() + "-" + bizOperator.getHlhtOperatorId() + ": assembleTokenResult response,:{},:{}", code, URL);

                            if (code == 200) {
                                HttpEntity entity = httpResponse.getEntity();
                                String result = EntityUtils.toString(entity, "UTF-8");
                                logger.info(URL + " assembleTokenResult 返回密文:{}", result);

                                if (StringUtils.isBlank(result)) {
                                    return null;
                                }

                                StdRequest tRequest = JSON.parseObject(result, StdRequest.class);
                                if (tRequest == null) {
                                    return null;
                                }

                                //根据对方ID对传来的信息进行签名校验
                                //boolean checkSig = HlhtPubFetchTool.checkSig2(hlhtOuter, tRequest);
                                //if (!checkSig) {
                                //    return null;
                                //}

                                //根据瑞晨的operatorID对合作方传来的信息进行解密
                                String deData = HlhtBizPubFetchTool.genDDDecodeData2(bizOperator, tRequest.getData());
                                tRequest.setData(deData);
                                logger.info(bizOperator.getTenantCode() + "-" + bizOperator.getHlhtOperatorId() + ": assembleTokenResult 返回明文:{},JSON:{},URL:{}", deData, enData, URL);

                                TokenResult tokenResult = JSON.parseObject(deData, TokenResult.class);
                                //ObjectMapper objectMapper = new ObjectMapper();
                                //String enData = objectMapper.writeValueAsString(tokenResult);

                                return tokenResult;
                            } else {
                                return null;
                            }
                        }
                    });


        }catch (Exception e){
            logger.error(bizOperator.getTenantCode() + "-" + bizOperator.getHlhtOperatorId() + ":assembleTokenResult 报错", e);
            logger.error(bizOperator.getTenantCode() + "-" + bizOperator.getHlhtOperatorId() + ":assembleTokenResult 报错", URL);
            return null;
        }
    }

    @Override
    public EquipAuthResult assembleEquipAuthResult(EquipAuthReq equipAuthReq, TokenResult tokenResult, HlhtskBizOperator bizOperator, HlhtskBizTenant bizTenant) {
        //推送地址
        String URL = bizOperator.getHlhtUrl2() + HlhtConfig.QUERY_EQUIP_AUTH2;

        try {
            ObjectMapper objectMapper = new ObjectMapper();
            String enData = objectMapper.writeValueAsString(equipAuthReq);
            logger.info(bizOperator.getTenantCode() + ":assembleEquipAuthResult 加密前:{}", enData);

            //使用对方密钥加密
            String retdata = HlhtBizPubFetchTool.genDDEncodeData2(bizOperator, enData);

            //使用对方密钥签名
            String timeStamp = sdf.format(System.currentTimeMillis());
            String sig = HlhtBizPubFetchTool.genDDSig2(bizOperator, retdata, timeStamp);

            StdRequest resp = genSuccessResp2(retdata, bizOperator, sig, timeStamp);

            String respData = objectMapper.writeValueAsString(resp);

            ////使用对方密钥加密
            //String retdata = HlhtBizPubFetchTool.genDDEncodeData(bizTenant, enData);
            //
            ////使用对方密钥签名
            //String timeStamp = sdf.format(System.currentTimeMillis());
            //String sig = HlhtBizPubFetchTool.genDDSig2(bizOperator, retdata, timeStamp);
            //
            //StdRequest resp = genSuccessResp2(retdata, bizOperator.getTenantCode(), sig, timeStamp);
            //
            //String respData = objectMapper.writeValueAsString(resp);

            logger.info(bizOperator.getTenantCode() + "-" + bizOperator.getHlhtOperatorId() + ":assembleEquipAuthResult 请求,:{},:{}", respData, URL);
            return Request.Post(URL)
                    .addHeader("Content-Type", HttpConstant.CONTENT_TYPE_JSON)
                    .addHeader("Authorization", HttpConstant.AUTHORIZATION_PREFIX + tokenResult.getAccessToken())
                    .body(new StringEntity(respData))
                    .execute()
                    .handleResponse(new ResponseHandler <EquipAuthResult>() {
                        @Override
                        public EquipAuthResult handleResponse(HttpResponse httpResponse) throws IOException {
                            int code = httpResponse.getStatusLine().getStatusCode();

                            logger.info(bizOperator.getTenantCode() + "-" + bizOperator.getHlhtOperatorId() + ": assembleEquipAuthResult response,:{},:{}", code, URL);

                            if (code == 200) {
                                HttpEntity entity = httpResponse.getEntity();
                                String result = EntityUtils.toString(entity, "UTF-8");
                                logger.info(URL + " assembleEquipAuthResult 返回密文:{}", result);

                                if (StringUtils.isBlank(result)) {
                                    return null;
                                }

                                StdRequest stdRequest = JSON.parseObject(result, StdRequest.class);
                                if (stdRequest == null) {
                                    return null;
                                }

                                //根据对方ID对传来的信息进行签名校验
                                //boolean checkSig = HlhtPubFetchTool.checkSig2(hlhtOuter, tRequest);
                                //if (!checkSig) {
                                //    return null;
                                //}

                                //根据瑞晨的operatorID对合作方传来的信息进行解密
                                String deData = HlhtBizPubFetchTool.genDDDecodeData2(bizOperator, stdRequest.getData());
                                stdRequest.setData(deData);
                                logger.info(bizOperator.getTenantCode() + "-" + bizOperator.getHlhtOperatorId() + ": assembleEquipAuthResult 返回明文:{},JSON:{},URL:{}", deData, enData, URL);

                                EquipAuthResult equipAuthResult = JSON.parseObject(deData, EquipAuthResult.class);
                                return equipAuthResult;
                            } else {
                                return null;
                            }
                        }
                    });

        } catch (Exception e) {
            logger.error(bizOperator.getTenantCode() + "-" + bizOperator.getHlhtOperatorId() + ":assembleEquipAuthResult 报错", e);
            logger.error(bizOperator.getTenantCode() + "-" + bizOperator.getHlhtOperatorId() + ":assembleEquipAuthResult 报错", URL);
            return null;
        }

    }

    @Override
    public EquipBusinessPolicyResult assembleEquipBusinessPolicyResult(EquipBusinessPolicyReq equipBusinessPolicyReq, TokenResult tokenResult, HlhtskBizOperator bizOperator, HlhtskBizTenant bizTenant) {
        //推送地址
        String URL = bizOperator.getHlhtUrl2() + HlhtConfig.QUERY_EQUIP_BUSINESS_POLICY2;

        try {
            ObjectMapper objectMapper = new ObjectMapper();
            String enData = objectMapper.writeValueAsString(equipBusinessPolicyReq);
            logger.info(bizOperator.getTenantCode() + ":assembleEquipBusinessPolicyResult 加密前:{}", enData);

            //使用对方密钥加密
            String retdata = HlhtBizPubFetchTool.genDDEncodeData2(bizOperator, enData);

            //使用对方密钥签名
            String timeStamp = sdf.format(System.currentTimeMillis());
            String sig = HlhtBizPubFetchTool.genDDSig2(bizOperator, retdata, timeStamp);

            StdRequest resp = genSuccessResp2(retdata, bizOperator, sig, timeStamp);

            String respData = objectMapper.writeValueAsString(resp);

            ////使用对方密钥加密
            //String retdata = HlhtBizPubFetchTool.genDDEncodeData(bizTenant, enData);
            //
            ////使用对方密钥签名
            //String timeStamp = sdf.format(System.currentTimeMillis());
            //String sig = HlhtBizPubFetchTool.genDDSig2(bizOperator, retdata, timeStamp);
            //
            //StdRequest resp = genSuccessResp2(retdata, bizOperator.getTenantCode(), sig, timeStamp);
            //
            //String respData = objectMapper.writeValueAsString(resp);

            logger.info(bizOperator.getTenantCode() + "-" + bizOperator.getHlhtOperatorId() + ":assembleEquipBusinessPolicyResult 请求,:{},:{}", respData, URL);
            return Request.Post(URL)
                    .addHeader("Content-Type", HttpConstant.CONTENT_TYPE_JSON)
                    .addHeader("Authorization", HttpConstant.AUTHORIZATION_PREFIX + tokenResult.getAccessToken())
                    .body(new StringEntity(respData))
                    .execute()
                    .handleResponse(new ResponseHandler <EquipBusinessPolicyResult>() {
                        @Override
                        public EquipBusinessPolicyResult handleResponse(HttpResponse httpResponse) throws IOException {
                            int code = httpResponse.getStatusLine().getStatusCode();

                            logger.info(bizOperator.getTenantCode() + "-" + bizOperator.getHlhtOperatorId() + ": assembleEquipBusinessPolicyResult response,:{},:{}", code, URL);

                            if (code == 200) {
                                HttpEntity entity = httpResponse.getEntity();
                                String result = EntityUtils.toString(entity, "UTF-8");
                                logger.info(URL + " assembleEquipBusinessPolicyResult 返回密文:{}", result);

                                if (StringUtils.isBlank(result)) {
                                    return null;
                                }

                                StdRequest stdRequest = JSON.parseObject(result, StdRequest.class);
                                if (stdRequest == null) {
                                    return null;
                                }

                                //根据对方ID对传来的信息进行签名校验
                                //boolean checkSig = HlhtPubFetchTool.checkSig2(hlhtOuter, tRequest);
                                //if (!checkSig) {
                                //    return null;
                                //}

                                //根据瑞晨的operatorID对合作方传来的信息进行解密
                                String deData = HlhtBizPubFetchTool.genDDDecodeData2(bizOperator, stdRequest.getData());
                                stdRequest.setData(deData);
                                logger.info(bizOperator.getTenantCode() + "-" + bizOperator.getHlhtOperatorId() + ": assembleEquipBusinessPolicyResult 返回明文:{},JSON:{},URL:{}", deData, enData, URL);

                                EquipBusinessPolicyResult equipBusinessPolicyResult = JSON.parseObject(deData, EquipBusinessPolicyResult.class);
                                return equipBusinessPolicyResult;
                            } else {
                                return null;
                            }
                        }
                    });

        } catch (Exception e) {
            logger.error(bizOperator.getTenantCode() + "-" + bizOperator.getHlhtOperatorId() + ":assembleEquipBusinessPolicyResult 报错", e);
            logger.error(bizOperator.getTenantCode() + "-" + bizOperator.getHlhtOperatorId() + ":assembleEquipBusinessPolicyResult 报错", URL);
            return null;
        }
    }

    @Override
    public StartChargeResult assembleStartChargeResult(StartChargeReq startChargeReq, TokenResult tokenResult, HlhtskBizOperator bizOperator, HlhtskBizTenant bizTenant) {
        //推送地址
        String URL = bizOperator.getHlhtUrl2() + HlhtConfig.QUERY_START_CHARGE2;

        try {
            ObjectMapper objectMapper = new ObjectMapper();
            String enData = objectMapper.writeValueAsString(startChargeReq);
            logger.info(bizOperator.getTenantCode() + ":assembleStartChargeResult 加密前:{}", enData);

            //使用对方密钥加密
            String retdata = HlhtBizPubFetchTool.genDDEncodeData2(bizOperator, enData);

            //使用对方密钥签名
            String timeStamp = sdf.format(System.currentTimeMillis());
            String sig = HlhtBizPubFetchTool.genDDSig2(bizOperator, retdata, timeStamp);

            StdRequest resp = genSuccessResp2(retdata, bizOperator, sig, timeStamp);

            String respData = objectMapper.writeValueAsString(resp);

            ////使用对方密钥加密
            //String retdata = HlhtBizPubFetchTool.genDDEncodeData(bizTenant, enData);
            //
            ////使用对方密钥签名
            //String timeStamp = sdf.format(System.currentTimeMillis());
            //String sig = HlhtBizPubFetchTool.genDDSig2(bizOperator, retdata, timeStamp);
            //
            //StdRequest resp = genSuccessResp2(retdata, bizOperator.getTenantCode(), sig, timeStamp);
            //
            //String respData = objectMapper.writeValueAsString(resp);

            logger.info(bizOperator.getTenantCode() + "-" + bizOperator.getHlhtOperatorId() + ":assembleStartChargeResult 请求,:{},:{}", respData, URL);
            return Request.Post(URL)
                    .addHeader("Content-Type", HttpConstant.CONTENT_TYPE_JSON)
                    .addHeader("Authorization", HttpConstant.AUTHORIZATION_PREFIX + tokenResult.getAccessToken())
                    .body(new StringEntity(respData))
                    .execute()
                    .handleResponse(new ResponseHandler <StartChargeResult>() {
                        @Override
                        public StartChargeResult handleResponse(HttpResponse httpResponse) throws IOException {
                            int code = httpResponse.getStatusLine().getStatusCode();

                            logger.info(bizOperator.getTenantCode() + "-" + bizOperator.getHlhtOperatorId() + ": assembleStartChargeResult response,:{},:{}", code, URL);

                            if (code == 200) {
                                HttpEntity entity = httpResponse.getEntity();
                                String result = EntityUtils.toString(entity, "UTF-8");
                                logger.info(URL + " assembleStartChargeResult 返回密文:{}", result);

                                if (StringUtils.isBlank(result)) {
                                    return null;
                                }

                                StdRequest stdRequest = JSON.parseObject(result, StdRequest.class);
                                if (stdRequest == null) {
                                    return null;
                                }

                                //根据对方ID对传来的信息进行签名校验
                                //boolean checkSig = HlhtPubFetchTool.checkSig2(hlhtOuter, tRequest);
                                //if (!checkSig) {
                                //    return null;
                                //}

                                //根据瑞晨的operatorID对合作方传来的信息进行解密
                                String deData = HlhtBizPubFetchTool.genDDDecodeData2(bizOperator, stdRequest.getData());
                                stdRequest.setData(deData);
                                logger.info(bizOperator.getTenantCode() + "-" + bizOperator.getHlhtOperatorId() + ": assembleStartChargeResult 返回明文:{},JSON:{},URL:{}", deData, enData, URL);

                                StartChargeResult startChargeResult = JSON.parseObject(deData, StartChargeResult.class);
                                return startChargeResult;
                            } else {
                                return null;
                            }
                        }
                    });

        } catch (Exception e) {
            logger.error(bizOperator.getTenantCode() + "-" + bizOperator.getHlhtOperatorId() + ":assembleStartChargeResult 报错", e);
            logger.error(bizOperator.getTenantCode() + "-" + bizOperator.getHlhtOperatorId() + ":assembleStartChargeResult 报错", URL);
            return null;
        }
    }

    @Override
    public EquipChargeStatusResult assembleEquipChargeStatusResult(EquipChargeStatusReq equipChargeStatusReq, TokenResult tokenResult, HlhtskBizOperator bizOperator, HlhtskBizTenant bizTenant) {
        //推送地址
        String URL = bizOperator.getHlhtUrl2() + HlhtConfig.QUERY_EQUIP_CHARGE_STATUS2;

        try {
            ObjectMapper objectMapper = new ObjectMapper();
            String enData = objectMapper.writeValueAsString(equipChargeStatusReq);
            logger.info(bizOperator.getTenantCode() + ":assembleEquipChargeStatusResult 加密前:{}", enData);

            //使用对方密钥加密
            String retdata = HlhtBizPubFetchTool.genDDEncodeData2(bizOperator, enData);

            String timeStamp = sdf.format(System.currentTimeMillis());
            //使用对方密钥签名
            String sig = HlhtBizPubFetchTool.genDDSig2(bizOperator, retdata, timeStamp);

            StdRequest resp = genSuccessResp2(retdata, bizOperator, sig, timeStamp);

            String respData = objectMapper.writeValueAsString(resp);

            logger.info(bizOperator.getTenantCode() + "-" + bizOperator.getHlhtOperatorId() + ":assembleEquipChargeStatusResult 请求,:{},:{}", respData, URL);
            return Request.Post(URL)
                    .addHeader("Content-Type", HttpConstant.CONTENT_TYPE_JSON)
                    .addHeader("Authorization", HttpConstant.AUTHORIZATION_PREFIX + tokenResult.getAccessToken())
                    .body(new StringEntity(respData))
                    .execute()
                    .handleResponse(new ResponseHandler <EquipChargeStatusResult>() {
                        @Override
                        public EquipChargeStatusResult handleResponse(HttpResponse httpResponse) throws IOException {
                            int code = httpResponse.getStatusLine().getStatusCode();

                            logger.info(bizOperator.getTenantCode() + "-" + bizOperator.getHlhtOperatorId() + ": assembleEquipChargeStatusResult response,:{},:{}", code, URL);

                            if (code == 200) {
                                HttpEntity entity = httpResponse.getEntity();
                                String result = EntityUtils.toString(entity, "UTF-8");
                                logger.info(URL + " assembleEquipChargeStatusResult 返回密文:{}", result);

                                if (StringUtils.isBlank(result)) {
                                    return null;
                                }

                                StdRequest stdRequest = JSON.parseObject(result, StdRequest.class);
                                if (stdRequest == null) {
                                    return null;
                                }

                                //根据对方ID对传来的信息进行签名校验
                                //boolean checkSig = HlhtPubFetchTool.checkSig2(hlhtOuter, tRequest);
                                //if (!checkSig) {
                                //    return null;
                                //}

                                //根据瑞晨的operatorID对合作方传来的信息进行解密
                                String deData = HlhtBizPubFetchTool.genDDDecodeData2(bizOperator, stdRequest.getData());
                                stdRequest.setData(deData);
                                logger.info(bizOperator.getTenantCode() + "-" + bizOperator.getHlhtOperatorId() + ": assembleEquipChargeStatusResult 返回明文:{},JSON:{},URL:{}", deData, enData, URL);

                                EquipChargeStatusResult equipChargeStatusResult = JSON.parseObject(deData, EquipChargeStatusResult.class);
                                return equipChargeStatusResult;
                            } else {
                                return null;
                            }
                        }
                    });
        }catch (Exception e){
            logger.error(bizOperator.getTenantCode() + "-" + bizOperator.getHlhtOperatorId() + ":assembleEquipChargeStatusResult 报错", e);
            logger.error(bizOperator.getTenantCode() + "-" + bizOperator.getHlhtOperatorId() + ":assembleEquipChargeStatusResult 报错", URL);
            return null;
        }
    }

    @Override
    public StopChargeResult assembleStopChargeResult(StopChargeReq stopChargeReq, TokenResult tokenResult, HlhtskBizOperator bizOperator, HlhtskBizTenant bizTenant) {
        //推送地址
        String URL = bizOperator.getHlhtUrl2() + HlhtConfig.QUERY_STOP_CHARGE2;

        try {
            ObjectMapper objectMapper = new ObjectMapper();
            String enData = objectMapper.writeValueAsString(stopChargeReq);
            logger.info(bizOperator.getTenantCode() + ":assembleStopChargeResult 加密前:{}", enData);

            //使用对方密钥加密
            String retdata = HlhtBizPubFetchTool.genDDEncodeData2(bizOperator, enData);

            //使用对方密钥签名
            String timeStamp = sdf.format(System.currentTimeMillis());
            String sig = HlhtBizPubFetchTool.genDDSig2(bizOperator, retdata, timeStamp);

            StdRequest resp = genSuccessResp2(retdata, bizOperator, sig, timeStamp);

            String respData = objectMapper.writeValueAsString(resp);

            ////使用对方密钥加密
            //String retdata = HlhtBizPubFetchTool.genDDEncodeData(bizTenant, enData);
            //
            ////使用对方密钥签名
            //String timeStamp = sdf.format(System.currentTimeMillis());
            //String sig = HlhtBizPubFetchTool.genDDSig2(bizOperator, retdata, timeStamp);
            //
            //StdRequest resp = genSuccessResp2(retdata, bizOperator.getTenantCode(), sig, timeStamp);
            //
            //String respData = objectMapper.writeValueAsString(resp);

            logger.info(bizOperator.getTenantCode() + "-" + bizOperator.getHlhtOperatorId() + ":assembleStopChargeResult 请求,:{},:{}", respData, URL);
            return Request.Post(URL)
                    .addHeader("Content-Type", HttpConstant.CONTENT_TYPE_JSON)
                    .addHeader("Authorization", HttpConstant.AUTHORIZATION_PREFIX + tokenResult.getAccessToken())
                    .body(new StringEntity(respData))
                    .execute()
                    .handleResponse(new ResponseHandler <StopChargeResult>() {
                        @Override
                        public StopChargeResult handleResponse(HttpResponse httpResponse) throws IOException {
                            int code = httpResponse.getStatusLine().getStatusCode();

                            logger.info(bizOperator.getTenantCode() + "-" + bizOperator.getHlhtOperatorId() + ": assembleStopChargeResult response,:{},:{}", code, URL);

                            if (code == 200) {
                                HttpEntity entity = httpResponse.getEntity();
                                String result = EntityUtils.toString(entity, "UTF-8");
                                logger.info(URL + " assembleStopChargeResult 返回密文:{}", result);

                                if (StringUtils.isBlank(result)) {
                                    return null;
                                }

                                StdRequest stdRequest = JSON.parseObject(result, StdRequest.class);
                                if (stdRequest == null) {
                                    return null;
                                }

                                //根据对方ID对传来的信息进行签名校验
                                //boolean checkSig = HlhtPubFetchTool.checkSig2(hlhtOuter, tRequest);
                                //if (!checkSig) {
                                //    return null;
                                //}

                                //根据瑞晨的operatorID对合作方传来的信息进行解密
                                String deData = HlhtBizPubFetchTool.genDDDecodeData2(bizOperator, stdRequest.getData());
                                stdRequest.setData(deData);
                                logger.info(bizOperator.getTenantCode() + "-" + bizOperator.getHlhtOperatorId() + ": assembleStopChargeResult 返回明文:{},JSON:{},URL:{}", deData, enData, URL);

                                StopChargeResult stopChargeResult = JSON.parseObject(deData, StopChargeResult.class);
                                return stopChargeResult;
                            } else {
                                return null;
                            }
                        }
                    });

        } catch (Exception e) {
            logger.error(bizOperator.getTenantCode() + "-" + bizOperator.getHlhtOperatorId() + ":assembleStopChargeResult 报错", e);
            logger.error(bizOperator.getTenantCode() + "-" + bizOperator.getHlhtOperatorId() + ":assembleStopChargeResult 报错", URL);
            return null;
        }
    }

    /**
     * 返回成功信息
     */
    private StdRequest genSuccessResp2(String data, HlhtskBizOperator bizOperator, String sig, String timeStamp) {
        StdRequest resp = new StdRequest();
        //{
        //    "Data": "R00qOvVMxZ79Iyl+hW2GOUuiv3+T9wPjG9sSzav2lGqkAzkSU6L7SXWUlsDJJFseECR7d1vFmn8sg9QsTgM8iRTlLB2oWbo7KSeTQIvovz0=",
        //        "OperatorID": "MA0019FW4",
        //        "Seq": "0219",
        //        "Sig": "A8ADF52A9A5394415A6D611CBFEFB205",
        //        "TimeStamp": "20171227174221"
        //}

        //SimpleDateFormat dateFormat = new SimpleDateFormat("yyyyMMddHHmmss");
        //String timeStamp = dateFormat.format(System.currentTimeMillis());
        resp.setTimeStamp(timeStamp);

        resp.setSig(sig);
        resp.setData(data);
        if (StringUtils.isBlank(bizOperator.getLicenseTenantCode())) {
            resp.setOperatorID(bizOperator.getTenantCode());
        } else {
            resp.setOperatorID(bizOperator.getLicenseTenantCode());
        }
        resp.setSeq("0001");
        return resp;
    }
}
